package es.puravida.watchuoc;

import org.apache.http.client.HttpClient;

import es.puravida.watchuoc.service.WatchUOCService;
import es.puravida.watchuoc.util.MyHTTPClient;
import android.app.Application;
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HTTP;

public class WatchUOCApplication extends Application {
	private static final String TAG = "ApplicationEx";

	private MyHTTPClient httpClient;

	@Override
	public void onCreate() {
		super.onCreate();
		httpClient = createHttpClient();
	}

	@Override
	public void onLowMemory() {
		super.onLowMemory();
		shutdownHttpClient();
	}

	@Override
	public void onTerminate() {
		super.onTerminate();
		shutdownHttpClient();
	}

	private MyHTTPClient createHttpClient() {
		MyHTTPClient ret = new MyHTTPClient(this);
		return ret;
	}

	public MyHTTPClient getHttpClient() {
		return httpClient;
	}

	private void shutdownHttpClient() {
		if (httpClient != null && httpClient.getConnectionManager() != null) {
			httpClient.getConnectionManager().shutdown();
		}
	}
}
